package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
import com.jiantong.work.enums.DocumentsDeleteFlag;
import com.jiantong.work.impl.dao.RetailImmunizationSubRecordDao;
import com.jiantong.work.model.RetailImmunizationSubRecord;
import com.jiantong.work.service.RetailImmunizationSubRecordReadService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by mz on 18/9/17.
 *
 */
@Slf4j
@Service
@RpcProvider
public class RetailImmunizationSubRecordReadServiceImpl implements RetailImmunizationSubRecordReadService{

    private final RetailImmunizationSubRecordDao retailImmunizationSubRecordDao;

    @Autowired
    public RetailImmunizationSubRecordReadServiceImpl(RetailImmunizationSubRecordDao retailImmunizationSubRecordDao) {
        this.retailImmunizationSubRecordDao = retailImmunizationSubRecordDao;
    }

    /**
     * 根据主表的ID
     * 查询字表数据的list
     *
     * @param vaccineId 主表id
     * @return Paging<RetailImmunizationSubRecord>
     */
    @Override
    public Response<List<RetailImmunizationSubRecord>> queryListByVaccineId(Long vaccineId) {
        try{
            Map<String , Object> criteria = Maps.newHashMap();
            criteria.put("vaccineId",vaccineId);
            criteria.put("deleteFlag", DocumentsDeleteFlag.NORMAL.value());
            return Response.ok(retailImmunizationSubRecordDao.queryList(criteria));
        }catch (Exception e){
            log.error("failed to query list, case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to query list");
        }
    }
}
